package com.ay.test;

import java.util.Observable;
import java.util.Observer;

/**
 * @Author: ay
 * @Date: 2021/3/5
 * @Description:
 **/
public class Main {

    public static void main(String[] args) {
        ConcreteSubject subject = new ConcreteSubject();
        Observer obs1 = new RealObserver1();
        Observer obs2 = new RealObserver2();
        subject.addObserver(obs1);
        subject.addObserver(obs2);
        subject.setNum(10);
        test(subject);
        subject.setNum(20);
        test(subject);
    }


    static void test(ConcreteSubject subject){
        System.out.println("总的观察者数量：" + subject.countObservers());
        System.out.println("被观察者是否发生变化：：" + subject.hasChanged());
        subject.changed();
        System.out.println("被观察者是否发生变化：：" + subject.hasChanged());
        subject.notifyObservers(subject);
    }
}
